package de.fhffm.scs.simulator.body;

import java.util.ArrayList;
import java.util.List;

import de.fhffm.scs.simulator.data.BloodSugarLevel;

public class BloodSugarLevelGenerator {

	public static void main(String[] args) {
		List<BloodSugarLevel> l = generateBloodSugarLevels(30, 80, 120);

		System.out.print("bsl=c(");
		for (BloodSugarLevel b : l) {
			System.out.print(b.getLevel());

			if (l.get(l.size() - 1).equals(b)) {
				System.out.print(")\n");
			} else {
				System.out.print(",");
			}
		}

		System.out.print("time=c(");
		for (BloodSugarLevel b : l) {
			System.out.print(b.getTimestamp());

			if (l.get(l.size() - 1).equals(b)) {
				System.out.print(")\n");
			} else {
				System.out.print(",");
			}
		}
		System.out.println("plot(time,bsl)\nres = lm(bsl~time)\nabline(res)");
	}

	public static List<BloodSugarLevel> generateBloodSugarLevels(int amount,
			int minLevel, int maxLevel) {
		List<BloodSugarLevel> l = new ArrayList<BloodSugarLevel>();

		int lastLevel = minLevel;

		long timestamp = System.currentTimeMillis();

		for (int i = 0; i < amount; i++) {
			timestamp += 50000; // increase by 5 sec

			double lessGreater = Math.random();

			if (lessGreater <= 0.2) {
				lastLevel = lastLevel - (int) (Math.random() * 10);
			} else {
				lastLevel = lastLevel + (int) (Math.random() * 10);
			}
			BloodSugarLevel bsl = new BloodSugarLevel(lastLevel, timestamp);
			l.add(bsl);
		}

		return l;
	}
}
